package com.lecture.javamode.oberver.eventbus;

import jline.internal.Preconditions;

import java.lang.reflect.Method;

public class ObserverAction {

    /**
     * 观察者类
     */
    private Object target;

    /**
     * 观察者的方法
     */
    private Method method;


    public ObserverAction(Object target,Method method) {
        this.target = Preconditions.checkNotNull(target);
        this.method = method;
        this.method.setAccessible(true);
    }

    /**
     * 执行观察者方法
     * @param event method方法的参数
     */
    public void execute(Object event) {
        try {
            method.invoke(target,event);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
